package com.example.controller;

import com.example.model.entity.user.User;
import com.example.organization.service.OrgService;
import com.example.service.SomeBusinessService;
import com.example.spi.ModuleService;
import com.example.spi.SpiServiceManager;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.List;

@RestController
@RequestMapping("/module")
@RequiredArgsConstructor
public class ModuleController {
    private final SpiServiceManager serviceManager;
    private final SomeBusinessService someBusinessService;
    private final OrgService orgService;


    @GetMapping("/test")
    public List<User> test() {
        System.out.println("测试提交");
        return orgService.getUsersInDepartment("123");
    }
    @GetMapping("/modules")
    public Collection<ModuleService> getAllModules() {
        return serviceManager.getAllServices();
    }

    @GetMapping("/doSomething")
    public String doSomething() {
        someBusinessService.doSomething();
        return "做了些事情";
    }

    @GetMapping("/doSomethingGeneric")
    public String doSomethingGeneric() {
        someBusinessService.doSomethingGeneric();
        return "doSomethingGeneric";
    }

    @GetMapping("/modules/{name}/execute")
    public String executeModule(@PathVariable String name) {
        serviceManager.executeService(name);
        return "执行模块: " + name;
    }
}